package com.demo.java.concurrent.threadpool;

import com.demo.java.utils.ThreadUtils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ThreadPoolException {
    public static void main(String[] args) {
//        final ExecutorService executorService = Executors.newSingleThreadExecutor();
        final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        /*executorService.submit(() -> {
            System.out.println("come in");
            throw new Exception("ttt");
        });*/
        try {
            scheduledExecutorService.scheduleWithFixedDelay(() -> {
                System.out.println("come in");
                throw new RuntimeException("test");
            }, 2, 2, TimeUnit.SECONDS);
        } catch (Exception ex) {
            System.out.println("error");
            ex.printStackTrace();
        }
        System.out.println("main sleep");
        ThreadUtils.sleep(2, TimeUnit.SECONDS);
    }
}
